home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4625 < prev    next >
Encoding:
Text File  |  1996-08-06  |  962 b   |  54 lines

  1. Path: in2.uu.net!saix!usenet
  2. From: Tiaan Wessels <tiaan>
  3. Newsgroups: comp.lang.c++
  4. Subject: (no subject)
  5. Date: 31 Jan 1996 12:21:12 GMT
  6. Organization: The South African Internet Exchange.
  7. Message-ID: <4enmro$kac@igubu.saix.net>
  8. NNTP-Posting-Host: tiaan.inetsys.alt.za
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.1N (X11; I; Linux 1.1.88 i486)
  13. X-URL: news:comp.lang.c++
  14.  
  15. I have a problem with overloading the << operator and would like some help
  16.  
  17. Th following code does not compile. Why ?
  18.  
  19. #include <iostream.h>
  20.  
  21. class Base
  22. {
  23. public:
  24.     Base() {}
  25.     
  26.     virtual ostream &operator << ( ostream & ) {}
  27. };
  28.  
  29. class Child : public Base
  30. {
  31.     int mine;
  32. public:
  33.     Child( int a )    { mine = a; }
  34.  
  35.     virtual ostream &operator << ( ostream &strm )
  36.     {
  37.         strm << mine;
  38.         return strm;
  39.     }
  40. };
  41.  
  42. void main()
  43. {
  44.     Child c( 5 );
  45.     cout << c;
  46. }
  47.  
  48. I'd appreciate any help.
  49. -- 
  50. Tiaan Wessels
  51. tiaan@inetsys.alt.za
  52. Netsys International
  53.  
  54.